package com.throttle.raildroid;


import java.util.ArrayList;

import sun.awt.windows.ThemeReader;
import android.app.Activity;
import android.app.LauncherActivity.ListItem;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class SelectActivity extends Activity {
	int logCount = 0;
	SelectActivity self;
	LinearLayout layout;
	TextView textView;
	private LogUpdater updater;
	private class LogUpdater implements Runnable{
		public void run() {
			while(true){
				if (StaticLogList.logList.size() > logCount){
					int i = logCount;
					int size = StaticLogList.logList.size();
					while(i < size){
						textView.setText(textView.getText()+StaticLogList.logList.get(i)+"\n");
						i++;
					}
					logCount = size;
				}
			}
		}
	}
	
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	this.self = this;
    	this.layout = new LinearLayout(this);
		textView = new TextView(self);
		textView.setText("AdaRail Log:\n");
		textView.setMovementMethod(new ScrollingMovementMethod());
		this.layout.addView(textView);
    	setContentView(this.layout);
        StaticLogList.testHandler.addRailEventListener(new RailEventListenerInf() {
			public void RailEventOccurred(RailEvent evt) {
				if (StaticLogList.logList.size() > logCount){
					int i = logCount;
					int size = StaticLogList.logList.size();
					while(i < size){
						textView.setText(textView.getText()+StaticLogList.logList.get(i)+"\n");
						i++;
					}
					logCount = size;
				}
			}
		});
        LogUpdater lu = new LogUpdater();
        new Thread(lu).start();
        
    }
}